package com.miaoji.aspect;
import com.miaoji.domain.po.Cloth;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ClothAspect {
    @AfterReturning(pointcut = "execution(* com.miaoji.service.ClothService.ClothInsert(..))",returning = "result")
    public void afterSuccessfulInsert(int result) {
        if(result>0){
            System.out.println("插入成功!");
        }
    }
    @AfterThrowing(pointcut = "execution(* com.miaoji.service.ClothService.ClothInsert(..))", throwing = "exception")
    public void afterFailedInsert(Exception exception) {
        System.out.println("插入失败：" + exception.getMessage());
    }
    @Before("execution(* com.miaoji.service.ClothService.ClothUpdate(..)) && args(cloth)")
    public void beforeClothUpdate(Cloth cloth) {
        System.out.println("Before updating cloth: " + cloth);
        // 在这里可以添加前置逻辑
    }

    @AfterReturning(pointcut = "execution(* com.miaoji.service.ClothService.ClothUpdate(..))", returning = "result")
    public void afterSuccessfulClothUpdate(Object result) {
        System.out.println("After updating cloth successfully. Result: " + result);
        // 在这里可以添加后置逻辑
    }
//删除
    @AfterReturning(pointcut = "execution(* com.miaoji.service.ClothService.ClothDelete(..))", returning = "deleteResult")
    public void afterSuccessfulClothDelete(Object deleteResult) {
        if (deleteResult != null && (int) deleteResult > 0) {
            System.out.println("Cloth delete successful.");
            // 在这里可以添加删除成功后的逻辑
        } else {
            System.out.println("Cloth delete failed or no records were deleted.");
            // 在这里可以添加删除失败后的逻辑
        }
    }
}

